//
//  SyncKeywordDataRequest.m
//  Grammar
//
//  Created by Rick on 7/11/13.
//
//

#import "SyncKeywordDataRequest.h"
#import "Keyword.h"
#import "KeywordManager.h"

@implementation SyncKeywordDataRequest


- (NSString*)getRequestUrl
{
    return [NSString stringWithFormat:@"%@%@",REQUEST_DOMAIN,@"keyword/syncKeywords.intf?"];
}

- (ITTRequestMethod)getRequestMethod
{
    return ITTRequestMethodGet;
}

- (void)processResult
{
    NSArray *findArray = [self.resultDic objectForKey:@"syncFind"];
    NSArray *updateArray = [self.resultDic objectForKey:@"syncUpdate"];
    NSArray *deleteArray = [self.resultDic objectForKey:@"syncDelete"];
    
    for (NSDictionary *aKeywordDic in findArray) {
        Keyword *aKeyword = [[Keyword alloc] initWithDataDic:aKeywordDic];
        [[KeywordManager sharedManager] addKeyword:aKeyword];
        [aKeyword release];
    }
    
    for (NSDictionary *aKeywordDic in updateArray) {
        Keyword *aKeyword = [[Keyword alloc] initWithDataDic:aKeywordDic];
        [[KeywordManager sharedManager] updateKeyword:aKeyword];
        [aKeyword release];
    }
    
    for (NSDictionary *aKeywordDic in deleteArray) {
        Keyword *aKeyword = [[Keyword alloc] initWithDataDic:aKeywordDic];
        [[KeywordManager sharedManager] removeKeyword:aKeyword];
        [aKeyword release];
    }
}
@end
